<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search :config="searchConfig" @getHeight="getHeight" @search="search"/>
    <!-- table区域-begin -->
    <div class="page_table">
      <vxe-grid
        ref="xGrid"
        v-bind="vexConfig"
        :align="left"
        :border="true"
        :checkbox-config="checkboxConfig"
        :columns="columns"
        :data="dataSource"
        :height="pageHeight-seachHeight-90"
        :loading="loading"
        :resizable="true"
        :showOverflow="true"
        :toolbar-config="tableToolbar"
        size="mini"
        @checkbox-change="selectChangeEvent"
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class="table-operator">
            <a-button type="primary" @click="handleAdd()">新增</a-button>
          </div>
        </template>
        <template #detail="{ row,rowIndex }">
          <a @click="handleDetail(row)">{{ row.configCode }}</a>
        </template>

        <template #metaInfo="{ row,record }">
          {{ row.cfType == 1 ? '字段' : row.cfType == 2 ? '属性' : '' }}
        </template>
        <template #metaInfo="{ row,record }">
          {{ row.showType == 1 ? '表单' : '列表' }}
        </template>
        <template #action="{ row:record }">
          <a @click="deployment(record)">生成</a>
          <a-divider type="vertical"/>
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a @click="handleDelete(record.id)">删除</a>
        </template>
        <template #pager>
          <vxe-pager :currentPage.sync="ipagination.current"
                     :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
                     :page-size.sync="ipagination.pageSize"
                     :pageSizes="ipagination.pageSizeOptions"
                     :total="ipagination.total" @page-change="handlePageChange">
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->
    <form-business-data-modal ref="modalForm" @ok="modalFormOk"></form-business-data-modal>
  </a-card>

</template>

<script>
import { filterObj } from '@/utils/util'
import { PageListMixin } from '@/mixins/PageListMixin'
import JEllipsis from '@/components/cn-form/JEllipsis'
import { postAction, getAction, downFile } from '@/api/manage'
import FormAddEdit from '@comp/view/base-crud/form/FormAddEdit'
import FormBusinessDataModal from '@views/activiti/form/FormBusinessDataModal'

export default {
  name: 'ModelList',
  mixins: [PageListMixin],
  components: {
    JEllipsis,
    FormBusinessDataModal
  },
  data() {
    return {
      //查询区域
      searchConfig: [
        {
          type: 'input',
          name: 'configName',
          placeholder: '配置名称'
        }
      ],
      // 表头
      columns: [
        {
          type: 'checkbox',
          width: 60,
          fixed: 'left'
        },
        {
          title: '配置编码',
          minWidth: 80,
          field: 'configCode',
          slots: { default: 'detail' }
        },
        {
          title: '配置名称',
          minWidth: 80,
          field: 'configName'
        },
        // {
        //   title: '配置类型',
        //   minWidth: 80,
        //   field: 'cfType',
        //   slots: {
        //     default: 'cfType'
        //   }
        // },
        {
          title: '关联映射配置编码',
          minWidth: 80,
          field: 'configRelCode',
        },
        {
          title: '配置Vo映射',
          minWidth: 80,
          field: 'mappingFieldName',
        },
        {
          title: '类型',
          minWidth: 80,
          field: 'showType',
          slots: {
            default: 'metaInfo'
          }
        },
        {
          title: '创建时间',
          minWidth: 80,
          field: 'createTime',
          // sorter:true
        },
        {
          title: '最后更新时间',
          minWidth: 120,
          field: 'updateTime',
        },
        {
          title: '操作',
          minWidth: 150,
          field: 'action',
          slots: {
            default: 'action'
          }
        }
      ],
      labelCol: {
        xs: { span: 1 },
        sm: { span: 2 }
      },
      wrapperCol: {
        xs: { span: 10 },
        sm: { span: 16 }
      },
      url: {
        list: window._CONFIG['domianActivitiURL'] + '/bsconfig/actBusinessConfig/findPageList',
        delete: window._CONFIG['domianActivitiURL'] + '/bsconfig/actBusinessConfig/delete',
        detail: window._CONFIG['domianActivitiURL'] + '/bsconfig/actBusinessConfig/getInfo',
        create: window._CONFIG['domianActivitiURL'] + '/bsconfig/actBusinessConfig/doBuild',
        // update: window._CONFIG['domianActivitiURL'] + '/designController/editor?modelId=',
        // img: window._CONFIG['domianActivitiURL'] + '/activiti/models/export',
      }
    }
  },
  methods: {
    deployment(row) {
      var _this = this
      var id = row.id
      this.$confirm({
        title: '确认生成?',
        content: `确认生成关联业务表？`,
        onOk() {
          _this.loading = true
          getAction(_this.url.create + '?id=' + id).then((res) => {
            if (res.success) {
              _this.$message.success(res.message)
              _this.loadData()
            } else {
              _this.$message.error(res.message)
            }
          }).finally(() => {
            _this.loading = false
          })
        },
      })
    },
    // async handleAdd(record = {}, title = '新增', disabled = false, disableSubmit = false) {
    //   if (record.id && this.url.detail) {
    //     const res = await getAction(this.url.detail, { id: record.id })
    //     if (res.success) {
    //       if (res.result) {
    //         record = res.result
    //       }
    //     }
    //   }
    //   let config = {
    //     title: title,
    //     width: 500,
    //     addOrUpdateUrl: `${window._CONFIG['domianActivitiURL']}/bsconfig/actBusinessConfig/saveOrUpdate`,  //审核地址
    //     method: 'post',
    //     labelCol: {
    //       xs: { span: 24 },
    //       sm: { span: 6 }
    //     },
    //     wrapperCol: {
    //       xs: { span: 24 },
    //       sm: { span: 16 }
    //     },
    //     list: [
    //       {
    //         label: '配置名称',
    //         type: 'input',
    //         placeholder: '配置名称',
    //         disabled: disabled,
    //         name: 'configName',  // 后台接受字段
    //         check: { rules: [{ required: true, message: '' }] }
    //       },
    //       {
    //         label: '映射配置编码',
    //         type: 'input',
    //         placeholder: '关联映射配置编码',
    //         disabled: disabled,
    //         name: 'configRelCode',  // 后台接受字段
    //         check: { rules: [{ required: true, message: '' }] }
    //       },
    //       {
    //         label: '类型',
    //         type: 'a-select',
    //         placeholder: '类型',
    //         disabled: disabled,
    //         name: 'showType',  // 后台接受字段
    //         option: [
    //           {
    //             name: '表单',
    //             value: 1
    //           },
    //           {
    //             name: '列表',
    //             value: 2
    //           }
    //         ],
    //         check: { rules: [{ required: true, message: '' }] }
    //       },
    //
    //       {
    //         label: '配置Vo映射',
    //         type: 'input',
    //         placeholder: '配置Vo映射',
    //         disabled: disabled,
    //         name: 'mappingFieldName',  // 后台接受字段
    //         check: { rules: [{ required: true, message: '' }] }
    //       },
    //     ]
    //   }
    //   this.$refs.formAdd.edit(record, config)
    //   this.$refs.formAdd.disableSubmit = disableSubmit
    // },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>